package com.sky.api.client.fallback;

import com.sky.api.client.ProductFeignClient;
import com.sky.api.domain.vo.DishVO;
import com.sky.api.domain.vo.SetmealVO;
import com.sky.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Map;

@Slf4j
public class ProductFallbackFactory implements FallbackFactory<ProductFeignClient> {
    @Override
    public ProductFeignClient create(Throwable cause) {
        return new ProductFeignClient() {
            @Override
            public Result<Integer> countSetmealByMap(@RequestParam("status") Integer status) {
                log.error("统计启售/停售套餐数量失败，{}", cause.getMessage());
                return Result.success(0);
            }

            @Override
            public Result<SetmealVO> getSetmealById(Long id) {
                log.error("根据ID获取套餐失败，{}", cause.getMessage());
                return Result.success(new SetmealVO());
            }

            @Override
            public Result<DishVO> getDishById(Long id) {
                log.error("根据ID获取菜品失败，{}", cause.getMessage());
                return Result.success(new DishVO());
            }

            @Override
            public Result<Integer> countDishByMap(@RequestParam("status") Integer status) {
                log.error("统计启售/停售菜品数量失败，{}", cause.getMessage());
                return Result.success(0);
            }
        };
    }
}
